package com.aa.studentmanage.main;

import com.aa.studentmanage.entity.AdminEntity;
import com.aa.studentmanage.entity.StudentEntity;

import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;

public class DataInt {
    /*
    * 数组储存学生
    * */
    public static final StudentEntity stuArrs[] = new StudentEntity[10];
    /*
    * 读取配置文件储存管理员数据
    * */
    public static AdminEntity adminEntity = null;
    /*
    * 初始化学号
    * */
    public static int stuId = 1001;
    /*
    * 初始数组下标
    * */
    public static int arrIndex = 0;

    /*
    * 读取配置文件给AdminEntity赋值
    * */
    static {
        String adminName = getProperties("adminName");
        String adminPwd = getProperties("adminPwd");
        if (adminName!=null&&adminPwd!=null){
            adminEntity = new AdminEntity(adminName,adminPwd);
        }
    }

    /*
    * 获取配置文件的方法
    * */
    public static String getProperties(String key){

        String value = null;
        try {
            FileInputStream fileInputStream = new FileInputStream("day1130\\src\\admin.properties");
            Properties properties = new Properties();
            properties.load(fileInputStream);
            value = properties.getProperty(key);
        }catch (IOException e){
            System.out.println("配置文件读取失败,请联系管理员!");
            System.exit(0);
        }
        return value;
    }
}
